#include "door.h"
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h> 

//void* handle = 0;

int load(){
   
   

}

Door::Door(){
    handle = dlopen("/home/linaro/libs/libplcommpro.so", RTLD_NOW);
    if(!handle){
        printf("dlopen so %derror%d%s\n",handle,errno,dlerror());
        return;
    }
    else{
        printf("dlopen ok\n");
    }
    
  
    /*根据动态链接库操作句柄与符号，返回符号对应的地址*/
    m_pConnect = (PConnect)dlsym(handle, "Connect");
    if(m_pConnect){
        printf("load connect ok\n");
    }
    else{
        printf("load connect failed %s\n",dlerror());
    }
    //return 0;
}

Door::~Door(){
    if(handle){
        dlclose(handle);
    }
}

int Door::Connect(const char *pPro){
    if(m_pConnect){
        //int err = 0;
        doorHandle = (void*)m_pConnect(pPro);
        
        if(doorHandle == 0){
            return -1;
        }
        return 0;
    }
    return -2;
}